package com.Properties;

import java.io.FileWriter;
import java.util.Properties;

/**
 * 需求:使用peoperties将键值对数据写入到属性文件中去
 */

public class PropertiesDemo1 {
    public static void main(String[] args) throws Exception {


        //1.创建一个Properties对象
        Properties properties=new Properties();

        //2.向Properties中存入键值对：可以使用put也可以使用setProperties方法，其实setProperties里面还是一个put方法
        //class Properties extends Hashtable<Object,Object>,这里的Key和Value可以是任意值
        properties.put("admin","123456");
        //使用setProperties方法向Properties中写入数据
        properties.setProperty("lingyi","123456");
        properties.setProperty("ting","011010");


        //3.使用store方法将键值对写入文件
        properties.store(new FileWriter("app/src/password.properties"),"this is a password");
        //#this is a password
        //#Sun Apr 10 21:49:19 CST 2022
        //admin=123456
        //lingyi=123456
        //ting=011010


    }
}
